//
//  Server.h
//  XXX
//
//  Created by Xiaoshiheng_pro on 2017/2/18.
//  Copyright © 2017年 Xiaoshiheng_pro. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "GCDAsyncSocket.h"

#import "AppDelegate.h"

@protocol ServerDelegate <NSObject>

@optional

///收到消息
- (void)serverSocket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;
///发送消息
-(void)serverSocket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag;
///建立连接
- (void)serverSocket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket;
///失去连接
- (void)serverSocketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err;

    
@end

@interface Server : NSObject

+ (instancetype)ServerInit;

//服务器socket（开放端口，监听客户端socket的链接）
@property (nonatomic) GCDAsyncSocket *serverSocket;
//接收到的客户端socket
@property (nonatomic) GCDAsyncSocket *clinetSocket;

@property (weak, nonatomic) id<ServerDelegate> delegate;

@end
